function form(formName,rule,minLength,maxLength,choiceList,required){
    this.formName=formName;
    this.rule=rule;
    this.minLength=minLength;
    this.maxLength=maxLength;
    this.choiceList=choiceList;
    this.required=required;
    
    this.dom={
        labelSpan:'',
        conBox:'',
        errBox:'',
        mainDiv:'',
    }
    this.setDom();
    addEvent(this.submitButton,'click',this.valid.bind(this))

    


}
form.prototype={
    
    setChildNode:{
        //表单名span
       
        setLabelSpan:function(){
            this.dom.labelSpan=document.createElement('label')
            this.dom.labelSpan.innerHTML=this.formName+':';
        },
        //内容div
       
        setConBox:function(){
            this.dom.conBox='';
            
            switch(this.formName){
                case '输入框':{
                    this.dom.conBox=document.createElement('input');
                   
                    /**
                     * 给输入框添加监听事件
                     */
                    addEvent(this.dom.conBox,'keyup',function(){
                       
                    })
                };break;
                case '单选框':{
                    this.dom.conBox=document.createElement('div');
                    for(var i=0;i<this.choiceList.length;i++){
                        var choiceRadio=document.createElement('input');
                        choiceRadio.type='radio'
                        var label=document.createElement('label')
                        label.innerHTML=choiceList[i]+':';
                        this.dom.conBox.appendChild(label);
                        this.dom.conBox.appendChild(choiceRadio);
                    }
                    var choiceRadioList=this.dom.conBox.getElementsByTagName('input');
                    listLimit(choiceRadioList);
                };break;
                case '复选框':{
                    this.dom.conBox=document.createElement('div');
                    for(var i=0;i<this.choiceList.length;i++){
                        var choiceRadio=document.createElement('input');
                        choiceRadio.type='radio'
                        var label=document.createElement('label')
                        label.innerHTML=choiceList[i]+':';
                        this.dom.conBox.appendChild(label);
                        this.dom.conBox.appendChild(choiceRadio);
                    }
                };break;
                case '下拉选择框':{
                    this.dom.conBox=document.createElement('select');
                        var option=document.createElement('option');
                        option.innerHTML='请选择';
                        option.value=0;
                        this.dom.conBox.appendChild(option);

                     for(var i=0;i<this.choiceList.length;i++){
                        var option=document.createElement('option');
                        option.value=i;
                        option.innerHTML=choiceList[i]+'';
                        this.dom.conBox.appendChild(option);
                        
                    }

                };break;
                case '文本域':{
                    this.dom.conBox=document.createElement('textarea');
                    this.dom.conBox.style.width='300px';
                    this.dom.conBox.style.height='50px';

                    

                }
            }
            this.dom.conBox.className="fCon";
        },
        //错误信息提示
        
        setErrBox:function(){
            this.dom.errBox=document.createElement('div');
            this.dom.errBox.className='fErr';

        },
        //主框
        
        setMainDiv:function(){
            this.dom.mainDiv=document.createElement('div');
            this.dom.mainDiv.className="fDiv"
            this.dom.mainDiv.appendChild(this.dom.labelSpan);
            this.dom.mainDiv.appendChild(this.dom.conBox);
            this.dom.mainDiv.appendChild(this.dom.errBox);
            
        }



    },
    setDom:function(){
        this.setChildNode.setLabelSpan.apply(this);
        this.setChildNode.setConBox.apply(this);
        this.setChildNode.setErrBox.apply(this);
        this.setChildNode.setMainDiv.apply(this);
        $('#formArea').appendChild(this.dom.mainDiv)
    },
    submitButton:$('#submit>button'),
    //表单的验证
    valid:function(){
        this.clearErrInfo();
        switch(this.formName){
            case '文本域':
            case '输入框':{
                //验证是否必须
                if(this.required){
                    if(this.dom.conBox.value==""||this.dom.conBox.value==undefined||this.dom.conBox.value==null){
                        this.dom.errBox.innerHTML="此项不能为空";
                        err(this.dom.conBox)
                        return false;
                    };
                      //验证最小长度
                    if((!this.dom.conBox.value) ||this.dom.conBox.value.length<this.minLength){
                        this.dom.errBox.innerHTML="不能小于最小长度（最小长度为"+this.minLength+"）";
                        err(this.dom.conBox)
                        return false;
                    }
                   
                }
                 //验证最大长度
                if(this.dom.conBox.value.length>this.maxLength){
                    this.dom.errBox.innerHTML="不能大于最大长度（最大长度为"+this.maxLength+"）";
                    err(this.dom.conBox)
                    return false;
                }
                
                if(this.formName=='文本域'){
                    return true;
                }
                if(validUtil.checkRule(this.dom.conBox,this.rule)){
                    return true;
                }else{
                    switch(this.rule){
                        case 'text':{
                            this.dom.errBox.innerHTML="仅能输入汉字、英文字母或数字";
                            err(this.dom.conBox)
                            return false;
                        };
                        case 'mail':{
                            this.dom.errBox.innerHTML="请输入正确的邮箱名（仅支持@XXX.com的邮箱）";
                            err(this.dom.conBox)
                            return false;
                        }
                        case 'phoneNumber':{
                            this.dom.errBox.innerHTML="请输入正确的电话号码（电话号码只能为数字）";
                            err(this.dom.conBox)
                            return false;
                        }case 'password':{
                            if(this.dom.conBox.value.length>8){
                                return true;
                            }else{
                                this.dom.errBox.innerHTML="密码不能少于8位，只能是数字或字母，必须以字母开头";
                                err(this.dom.conBox)
                                return false;
                            }
                        }
                    }
                        
                }

                

                   
              
            };break;
            case '单选框':{
                //验证是否必填
                if(this.required){
                    if(!validUtil.checkRadioRequire(this.dom.conBox)){
                        this.dom.errBox.innerHTML="此项不能为空";
                        err(this.dom.conBox)
                        return false;
                    }
                }
            
            }
        }
    },
    clearErrInfo:function(){
        this.dom.errBox.innerHTML="";
        err(this.dom.conBox,true)
        return false;
    }

   
}